<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css/style_user2.css">
    <script src="__STATIC__/js/jquery-1.8.2.js"></script>
    <script src="__STATIC__/js/dialog/js/mh_dialog.js"></script>
    <script src="__STATIC__/password/passwordBox.min.js"></script>
    <script src="__STATIC__/password/md5.js"></script>
    <title>忘记支付密码</title>
</head>
<body>
<div class="wrap-phone">
    <div class="header">
        <p>验证手机号</p>
        <img src="__STATIC__/img/back.png" class="back">
    </div>
    <form action="" method="post" id="form" onsubmit="return false">
        <div class="center">
            <div>
                <input class="text" type="text" name="mobile" placeholder="手机号码" datatype="m" errormsg="号码格式不正确"
                       nullmsg="请填写新的绑定手机号码">
            </div>
            <div>
                <input class="text" type="text" name="code" placeholder="验证码" datatype="n4" nullmsg="请填写验证码"
                       errormsg="请填写4位纯数字">
                <span><a onclick="check_num();" id="yzm">验证码</a></span>
            </div>
        </div>
        <input type="button" class="submit"  value="下一步">
    </form>
</div>
{include file="public/src" /}
<script>

    // 输入内容判断
    $(function () {
        $.Tipmsg.r = null;
        $.Tipmsg.p = null;
        $.Datatype.n4 = /^\d{4}$/;
        var ajax = $("#form").Validform({
            tiptype: function (msg) {
                layer.open({content: msg, skin: 'msg', time: 2});
            },
            btnSubmit: '.submit',
            tipSweep: true,
            ajaxPost: true,
            callback:function (t) {
                if (t.code != 200){
                    layer.open({content:t.message,skin:'msg',time:2});
                }else{
                    mh_dialogShow('mh_success',t.message,2,true,"{:url('mobile/pay_pass/reset')}");
                }
            }
        });
        ajax.config({
            url:"{:url('mobile/pay_pass/bind_act')}",
            ajaxpost:{
                error: function () {
                    layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
                }
            }
        });
    });

    //发送验证码
    function check_num() {
        var tel = '';

        tel = $("[name='mobile']").val();

        if (tel == '') {
            layer.open({content: '请输入手机号', skin: 'msg', time: 2});
            return false;
        }
        if (!(/^1(3|4|5|7|8)\d{9}$/.test(tel))) {
            layer.open({content: '手机号格式不正确', skin: 'msg', time: 2});
            return false;
        }
        if (!check_unique(tel)) {
            return false;
        }

        count_down();
        $.ajax({
            url: "{:url('mobile/pay_pass/getVerif')}",
            dataType: 'json',
            type: 'post',
            data: {'tel': tel},
            success: function (t) {
                if (t.code != 200) {
                    layer.open({
                        content: t.message
                        , btn: '我知道了'
                    });
                }
            },
            error: function () {
                layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
            }
        })
    }

    //验证码倒计时
    function count_down() {
        var num = 60;
        var verif = $('#yzm');
        var timer = setInterval(function () {
            verif.text(num + '秒');
            if (num <= 60 && num >= 1) {
                verif.removeAttr('href');
            } else {
                verif.text('重新获取验证码');
                window.clearInterval(timer);
                verif.attr("href", 'javascript:check_num();');
            }
            num--;
        }, 1000);
    }

    //检测新绑定的手机号码的正确性
    function check_unique(tel) {
        var flag = true;
        $.ajax({
            url: "{:url('mobile/pay_pass/bind_phone')}",
            type: 'post',
            async: false,
            dateType: 'json',
            data: {'tel': tel},
            success: function (t) {
                if (t.code != 200) {
                    layer.open({content: t.message, skin: 'msg', time: 2});
                    flag = false;
                }
            },
            error: function () {
                layer.open({content:'网络繁忙,请重试',skin:'msg',time:2});
            }
        });
        return flag;
    }

</script>
</body>

</html>